<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\common\controller\Admin;
use think\Request;

class Banner extends Admin
{
    protected $with = ['ad'];
    public function initialize()
    {
        $this->menu_input = [
            'all' => [
                ['type' => 'select', 'name' => '所属栏目', 'key' => 'ad_id','verify'=>'required',
                    'select'=>[
                        'table'=>'Ad'
                    ]
                ],
                ['type' => 'y_image', 'name' => '图片', 'key' => 'image','verify'=>'required'],
                ['type' => 'radio', 'name' => '是否显示', 'key' => 'is_show','verify'=>'required','required'=>1,'data'=>[1=>'显示',2=>'不显示']],
                ['type' => 'text', 'name' => '排序', 'key' => 'sort'],
            ],
            'add' => [
            ],
            'upload' => [
            ],
        ];
        parent::initialize(); // TODO: Change the autogenerated stub
    }
    public function table_mage(&$data = [])
    {
        $data = [
            ['field' => 'ad_name', 'title' => '所属栏目'],
            ['field' => 'name', 'title' => '图片', 'templet' => '#list_image'],
            ['field' => 'create_time', 'title' => '添加时间'],
            ['field' => 'update_time', 'title' => '修改时间'],
            ['title' => '操作', 'templet' => '#list_setting']
        ];
        return parent::table_mage($data); // TODO: Change the autogenerated stub
    }
    public function index_handle(&$data)
    {
        $data['data'] = array_map(function($v){
            $v['ad_name'] = $v['ad']['name'];
            return $v;
        },$data['data']);
        return parent::index_handle($data); // TODO: Change the autogenerated stub
    }
}
